//
//  EmployeeOrderDetailVC.m
//  ForestPack
//
//  Created by jimmy on 2018/7/23.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#pragma mark - 这个是1.设计师中标后雇主的订单（同意，不同意议价的界面），和2.设计师投标的界面， 还有3.议价的界面 ，还有4.比稿设计选合作人的订单详情界面 ， 还有5.系统派单（雇主）界面， 6.系统派单（设计师）界面 7.竞标的界面  8.系统派单雇佣订单  

#import "EmployeeOrderDetailVC.h"
#import "EmployeeOrderDetailCell.h"
#import "OrderDetailFirstCell.h"
#import "DesignerGoodsCell.h"
#import "OrderDetailHeaderView.h"
#import "BilledPieceCell.h"
#import "SystemEmployerCell.h"
#import "UIView+Utils.h"

@interface EmployeeOrderDetailVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)  BaseTableView  * tableView;

@end

@implementation EmployeeOrderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setTitle:@"订单详情"];
    [self setTableViewUI];
    
    [self requestDesignOrderListDetailData];
}

-(void)setTableViewUI
{
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
//        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//    }
//    if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
//        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//    }
    [self.view addSubview:self.tableView];
    
}

#pragma mark - 设计订单列表的订单详情
-(void)requestDesignOrderListDetailData
{
    WeakObj(self);
    NSString *url = [NSString stringWithFormat:@"%@app/design_order_detail",REQUESTHEADER];
    NSDictionary *dict = @{@"id":@(self.design_id),@"token":[FPLoginAndRegisterTools getToken]};
    [HttpManager postHttpRequestByPost:url andParameter:dict success:^(id successResponse) {
        NSDictionary * dic = successResponse;
        NSString *status = [NSString stringWithFormat:@"%@",dic[@"status"]];
        if ([status isEqualToString:@"1"]) {
//            NSError *error;
//            selfWeak.shopOrderDetailModel = [[ShopOrderDetailModel alloc] initWithDictionary:dic[@"data"] error:&error];
//            [selfWeak.shopOrderDetailArray addObject:selfWeak.shopOrderDetailModel];
            [selfWeak.tableView reloadData];
            
        }else{
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

#pragma mark - tableView的delegate和datasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//    if (系统派单（设计师）) {
//        return 2;
//    }
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2) {
        //if (同不同意议价) {
        //      return 1;
        //}else if(设计师投标){
        //      return 6;//根据请求数据
        //}else if(比稿设计){
        //      return 6;//根据请求数据
        //}else if(系统派单（雇主）|| 竞标 || 系统派单雇佣订单){
        //      return 1;
        //}else if(系统派单（设计师）){
        //      return 1;
        //}else{//议价
        //      return 1;
        //}
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            return 2;
        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
            return 2;
        }
        return 1;
    }
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 108;
    }else if (indexPath.section == 1){
        return 130;
    }else{
        //if (同不同意议价) {
        //      return 425;
        //}else if(设计师投标){
        //      return 192;
        //}else if(比稿设计){
        //      return 44;//根据请求数据
        //}else if(系统派单（雇主){
        //      return 78;
        //}else if(系统派单雇佣订单){
        //      return 220;
        //}else if(系统派单（设计师）){
        //      return 0.01;
        //}else{//议价
        //      return 367;
        //}
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            return 210;
        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
            return 210;
        }
        return 44;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        //if(系统派单（雇主）|| 系统派单（设计师 || 竞标 || 系统派单雇佣订单){
        //      return 0.01;
        //}else{
        //      return 78;
        //}
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            return 78;
        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
            return 78;
        }
        return 0.01;
    }else if (section == 2){
        //if (同不同意议价) {
        //      return 44;
        //}else if(设计师投标){
        //      return 44;
        //}else if(比稿设计){
        //      return 44;//根据请求数据
        //}else if(系统派单（雇主）|| 系统派单雇佣订单){
        //      return 44;
        //}else if(系统派单（设计师）){
        //      return 0.01;
        //}else{//议价
        //      return 0.01;
        //}
        
        return 44;
    }else{
        
        return 0.01;
    }
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        //if(系统派单（雇主）|| 系统派单（设计师 || 系统派单雇佣订单){
        //      UIView *view = [[UIView alloc] init];
        //      return view;
        //}else{
//              OrderDetailHeaderView *headerView = [OrderDetailHeaderView headerViewWithHeight:78];
//              headerView.backgroundColor = [UIColor whiteColor];
//              return headerView;
        //}
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            OrderDetailHeaderView *headerView = [OrderDetailHeaderView headerViewWithHeight:78];
            headerView.backgroundColor = [UIColor whiteColor];
            return headerView;
        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
            OrderDetailHeaderView *headerView = [OrderDetailHeaderView headerViewWithHeight:78];
            headerView.backgroundColor = [UIColor whiteColor];
            return headerView;
        }
        UIView *view = [[UIView alloc] init];
        return view;

    }else if (section == 1){
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            UIView *view = [[UIView alloc] init];
            return view;
        }
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        return view;
    }else{
        UIView *view = [[UIView alloc] init];
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(13, 10, 80, 24);
        label.textAlignment = NSTextAlignmentLeft;
        label.font = Kfont(14);
        label.textColor = FONTCOLOR_BLACK;
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            label.text = @"竞标人";
        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
            label.text = @"竞标人";
        }
        else{
            label.text = @"中标人";
        }
        [view addSubview:label];
        UILabel *lineLabel = [[UILabel alloc] init];
        lineLabel.frame = CGRectMake(0, 43, SCREEN_WIDTH, 1);
        lineLabel.backgroundColor = LineColor;
        [view addSubview:lineLabel];
        view.backgroundColor = [UIColor whiteColor];
        return view;
        
        //if (同不同意议价) {
        //      label.text = @"中标人";
        //      return view;
        //}else if(设计师投标 || 比稿设计 || 竞标){
        //      label.text = @"竞标人";
        //      return view;
        //}else if(系统派单（雇主）|| 系统派单雇佣订单){
        //      label.text = @"设计师";
        //      return view;
        //}else if(系统派单（设计师）){
        //      return view;
        //}else{//议价
        //      return view;
        //}
        
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        return 200;
    }
    return 10;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section == 2) {
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            UIView *view = [[UIView alloc] init];
            return view;
        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
            UIView *view = [[UIView alloc] init];
            return view;
        }
        else{
            UIView *view = [[UIView alloc] init];
            OperateButton *button = [OperateButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(13, 50, SCREEN_WIDTH - 26, 44);
            [button setTitle:@"投标" forState:UIControlStateNormal];
            [view addSubview:button];
            view.backgroundColor = [UIColor whiteColor];
            return view;
        }
        //if (同不同意议价) {
        //      UIView *view = [[UIView alloc] init];
        //      return view;
        //}else if(设计师投标){
        //      UIView *view = [[UIView alloc] init];
        //      OperateButton *button = [OperateButton buttonWithType:UIButtonTypeCustom];
        //      button.frame = CGRectMake(13, 50, SCREEN_WIDTH - 26, 44);
        //      [button setTitle:@"投标" forState:UIControlStateNormal];
        //      [view addSubview:button];
        //      view.backgroundColor = [UIColor whiteColor];
        //      return view;
        //}else if(比稿设计){
        //      UIView *view = [[UIView alloc] init];
        //      OperateButton *button = [OperateButton buttonWithType:UIButtonTypeCustom];
        //      button.frame = CGRectMake(13, 50, SCREEN_WIDTH - 26, 44);
        //      [button setTitle:@"确定" forState:UIControlStateNormal];
        //      [view addSubview:button];
        //      view.backgroundColor = [UIColor whiteColor];
        //      return view;
        //}else if(系统派单（雇主）|| 竞标 || 系统派单雇佣订单){
        //      return view;
        //}else if(系统派单（设计师）){
        //      UIView *view = [[UIView alloc] init];
        //      OperateButton *button = [OperateButton buttonWithType:UIButtonTypeCustom];
        //      button.frame = CGRectMake(13, 50, SCREEN_WIDTH - 26, 44);
        //      [button setTitle:@"提交稿件" forState:UIControlStateNormal];
        //      [view addSubview:button];
        //      view.backgroundColor = [UIColor whiteColor];
        //      return view;
        //}else{//议价
        //      UIView *view = [[UIView alloc] init];
        //      return view;
        //}

        //        OperateButton *button = [OperateButton buttonWithType:UIButtonTypeCustom];
//        button.frame = CGRectMake(13, 50, SCREEN_WIDTH - 26, 44);
//        [button setTitle:@"确定" forState:UIControlStateNormal];
//        [view addSubview:button];
//        view.backgroundColor = [UIColor whiteColor];

    }
    UIView *view = [[UIView alloc] init];
    return view;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        OrderDetailFirstCell *cell = [OrderDetailFirstCell cellWithTableView:tableView indexPath:indexPath];
        return cell;
    }else if (indexPath.section == 1){
        OrderInfoCell *cell = [OrderInfoCell cellWithTableView:tableView indexPath:indexPath];
        return cell;
    }else{
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"2"]) {
            DesignerGoodsCell *cell = [DesignerGoodsCell cellWithTableView:tableView indexPath:indexPath rightBtnTitle:@"确认合作"];
            cell.yesBtn.hidden = YES;
            cell.noBtn.hidden = YES;
            cell.contactBtn.hidden = YES;
            cell.moneyLabel.hidden = YES;
            return cell;
        }
        if ([self.type isEqualToString:@"设计订单详情"] && [self.design_status isEqualToString:@"1"]) {
            DesignerGoodsCell *cell = [DesignerGoodsCell cellWithTableView:tableView indexPath:indexPath rightBtnTitle:@"确认合作"];
            cell.yesBtn.hidden = YES;
            cell.noBtn.hidden = YES;
            cell.contactBtn.hidden = YES;
            cell.moneyLabel.hidden = YES;
            return cell;
        }
        SystemEmployerCell *cell = [SystemEmployerCell cellWithTableView:tableView indexPath:indexPath];
        cell.finishBtn.hidden = NO;
        //        BilledPieceCell *cell = [BilledPieceCell cellWithTableView:tableView indexPath:indexPath];
        return cell;

    }
            //if (同不同意议价) {
//              DesignerGoodsCell *cell = [DesignerGoodsCell cellWithTableView:tableView indexPath:indexPath rightBtnTitle:@"确认合作"];
//              cell.contactBtn.hidden = YES;
//              return cell;
        //}else if(设计师投标){
        //      DesignerGoodsCell *cell = [DesignerGoodsCell cellWithTableView:tableView indexPath:indexPath];
        //      cell.yesBtn.hidden = YES;
        //      cell.noBtn.hidden = YES;
        //      cell.contactBtn.hidden = YES;
        //      cell.moneyLabel.hidden = YES;
        //      return cell;
        //}else if(竞标){
//              DesignerGoodsCell *cell = [DesignerGoodsCell cellWithTableView:tableView indexPath:indexPath rightBtnTitle:@"已完成"];
        //      cell.yesBtn.hidden = YES;
        //      cell.noBtn.hidden = YES;
        //      cell.contactBtn.hidden = NO;
        //      cell.moneyLabel.hidden = YES;
        //      return cell;
        //}else if(比稿设计){
        //      BilledPieceCell *cell = [BilledPieceCell cellWithTableView:tableView indexPath:indexPath];
        //      return cell;
        //}else if(系统派单（雇主){
        //      SystemEmployerCell *cell = [SystemEmployerCell cellWithTableView:tableView indexPath:indexPath];
        //      cell.finishBtn.hidden = YES;
        //      return cell;
        //}else if(系统派单雇佣订单){
        //      SystemEmployerCell *cell = [SystemEmployerCell cellWithTableView:tableView indexPath:indexPath];
        //      cell.finishBtn.hidden = NO;
        //      return cell;
        //}else if(系统派单（设计师）){
        //      return nil;
        //}else{//议价
        //      EmployeeOrderDetailCell *cell = [EmployeeOrderDetailCell cellWithTableView:tableView indexPath:indexPath];
        //      cell.sureBtn.hidden = NO;
        //      cell.sureEmployeBtn.hidden = YES;
        //      cell.refuseBtn.hidden = YES;
        //      return cell;
        //}
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:false];
}


@end
